package com.hdax.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdax.dm.dao.item.DmItemCommentMapper;
import com.hdax.dm.entity.item.DmItemComment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/comment")
@Api(value = "影剧影评测试接口",tags = "影剧影评测试接口")
public class DmItemCommentRestService {

    @Resource
    private DmItemCommentMapper dmItemCommentMapper;

    @ApiOperation(value = "查询影剧影评信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId",value = "",type = "Long")
    })
    @PostMapping(path = "/dmItemComment")
    public List<DmItemComment> dmItemComment(@RequestParam("itemId")Long itemId){
        QueryWrapper<DmItemComment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("itemId",itemId);
        queryWrapper.orderByDesc("createdTime");
        IPage<DmItemComment> iPage = new Page<>(0,10);
        return dmItemCommentMapper.selectPage(iPage,queryWrapper).getRecords();
    }

    //添加剧评
    @PostMapping(path = "/addComments")
    public int addComments(@RequestBody DmItemComment dmItemComment){
        return dmItemCommentMapper.insert(dmItemComment);
    }
}
